package com.ds.infrastructure.hyperspace.container.internal.transport;

import com.ds.infrastructure.hyperspace.container.internal.HyperspaceThreadFactory;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerSocketChannel;
import io.netty.channel.epoll.EpollSocketChannel;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.SocketChannel;

/**
 * @author  Weishaoying
 */
public class LinuxNativeTransportFactory implements NettyTransportFactory<EpollEventLoopGroup> {

    @Override
    public Class<? extends SocketChannel> socketChannelClass() {
        return EpollSocketChannel.class;
    }

    @Override
    public Class<? extends ServerSocketChannel> serverSocketChannelClass() {
        return EpollServerSocketChannel.class;
    }

    @Override
    public EpollEventLoopGroup newEventLoopGroup(HyperspaceThreadFactory threadFactory, int threadNum) {
        return new EpollEventLoopGroup(threadNum, threadFactory);
    }

    @Override
    public EpollEventLoopGroup newAcceptorEventLoopGroup(HyperspaceThreadFactory threadFactory, int threadNum) {
        EpollEventLoopGroup epollEventLoopGroup = newEventLoopGroup(threadFactory, threadNum);
        epollEventLoopGroup.setIoRatio(100);
        return epollEventLoopGroup;
    }
}
